package com.accompany.controller;


import com.accompany.common.result.CommonResult;
import com.accompany.model.Order;
import com.accompany.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author lfs
 * @since 2023-03-08
 */
@Api(tags = {"订单"})
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService service;

    @ApiOperation("下单")
    @PostMapping(value = "createOrder")
    public CommonResult createOrder(@RequestBody Order order){
        if (order==null){
            return CommonResult.failed("订单不能为空");
        }
        boolean insert = service.save(order);
        if (insert){
            return CommonResult.success(order);
        }else {
            return CommonResult.failed("创建订单失败");
        }
    }
}
